package com.kinyx.framework.db;

import java.io.IOException;

import javax.lang.model.element.TypeElement;

import com.kinyx.framework.processor.Context;
import com.kinyx.framework.processor.TypeElementWrapper;

public class EntityTypeElement extends TypeElementWrapper {

	public EntityTypeElement(final Context context, final TypeElement element) { super(context, element); }

	private boolean generated;

	public void generate() {
		if (this.generated) {
			this.context.getLogger().NOTE("EntityTypeElement.generate -> TypeElement[" + this.element + "] already generated");
			return;
		}
		this.context.getLogger().NOTE("EntityTypeElement.generate -> TypeElement[" + this.element + "] generate start");
		try {
			DBResourceGenerator.generate(this.context, this);
		} catch (final IOException e) {
			this.context.getLogger().ERROR("EntityTypeElement.generate -> TypeElement[" + this.element + "] throws Exception[" + e.getMessage() + "]", this.element);
			e.printStackTrace();
			return;
		}
		this.generated = true;
		this.context.getLogger().NOTE("EntityTypeElement.generate -> TypeElement[" + this.element + "] generate finished");
	}

}
